package com.xbongbong.pro.statistic.help.strategy.method;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.statistic.help.strategy.field.FieldAnalysisStrategy;
import com.xbongbong.pro.statistic.pojo.FieldAnalysisPojo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.domain.entity.ProductCategoryEntity;
import com.xbongbong.saas.model.ProductCategoryModel;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zcp
 */

@Component
public class PurchaseableGoodsFieldAnalysis implements FieldAnalysisStrategy {

    @Resource
    private ProductCategoryModel productCategoryModel;
    @Override
    public Map<String, String> doAnalysisField(FieldAnalysisPojo fieldAnalysisPojo) throws XbbException {
        Map<String, String> results = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        String corpid = fieldAnalysisPojo.getCorpid();
        Map<String, Object> params = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        params.put(StringConstant.CORPID, corpid);
        params.put("del", BasicConstant.ZERO);
        List<ProductCategoryEntity> productCategoryEntityList = productCategoryModel.findEntitys(params);
        productCategoryEntityList.forEach(item -> {
            results.put(item.getId().toString(), item.getName());
        });
        return results;
    }
}
